package oop.core;

/**
 * Class encapsulating an object that implements
 * an Updateable interface along with a time stamp.
 * @author DangMH
 *
 */
public class UpdateableObject {
	private long timeLeft;		// timestamp for notification period
	private Updateable obj;		// object to be notified
	
	/**
	 * Empty constructor.
	 */
	public UpdateableObject()
	{
		timeLeft = 0;
		obj = null;
	}
	
	/**
	 * Parameterized constructor.
	 * @param timeLeft
	 * @param obj
	 */
	public UpdateableObject( Updateable obj, long timeLeft )
	{
		this.timeLeft = timeLeft;
		this.obj = obj;
	}
	
	/**
	 * Operation to update and execute
	 * @param updateTime
	 * @return
	 */
	public boolean update( long updateTime )
	{
		timeLeft -= updateTime;
		
		if( timeLeft <= 0 )
		{
			obj.update();
		}
		
		return timeLeft <= 0;
	}
}
